package com.imay.live.adapter;

import android.view.MotionEvent;
import android.view.View;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.imay.live.R;
import com.imay.live.view.custom.BuyMViewModel;

import java.util.List;

/**
 * Created by liangzhenxiong on 2017/4/6 0006.
 * 充值
 */

public class BuyLinearAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {


    public final static int VIEWTYPE_PRICE = 3;//价钱


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public BuyLinearAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(VIEWTYPE_PRICE, R.layout.item_buy_price);
    }


    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item) {
        if (item.getItemType() == VIEWTYPE_PRICE) {
            if (item instanceof BuyMViewModel) {
                helper.addOnClickListener(R.id.tv_buy);
                BuyMViewModel buyMViewModel = (BuyMViewModel) item;
                helper.setText(R.id.tv_price, buyMViewModel.getMeili() + helper.getConvertView().getResources().getString(R.string.meili));
                helper.setText(R.id.tv_des, helper.getConvertView().getResources().getString(R.string.meizuan));
                helper.setText(R.id.tv_num, String.valueOf(buyMViewModel.getDiamond()));
                if (buyMViewModel.isChecked()) {
                    helper.setTextColor(R.id.tv_buy, helper.getConvertView().getResources().getColor(R.color.text_30));
                    helper.setBackgroundRes(R.id.tv_buy, R.drawable.shape_blue);
                    helper.getView(R.id.tv_buy).setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                                helper.setBackgroundRes(R.id.tv_buy, R.drawable.shape_corner100_30);
                                helper.setTextColor(R.id.tv_buy, helper.getConvertView().getResources().getColor(R.color.bg_window));
                            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                                helper.setBackgroundRes(R.id.tv_buy, R.drawable.shape_blue);
                                helper.setTextColor(R.id.tv_buy, helper.getConvertView().getResources().getColor(R.color.text_30));
                            }
                            return false;
                        }
                    });
                } else {
                    helper.setTextColor(R.id.tv_buy, helper.getConvertView().getResources().getColor(R.color.line_e5));
                    helper.setBackgroundRes(R.id.tv_buy, R.drawable.shape_enable_rechare);
                }
            }

        }

    }
}
